// pages/user_center/browse_record/browse_record.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData: 0,
    selectPerson: true,
    browseList: [],
    courseData: [],
    activityData: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '浏览记录',
    })
    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideShareMenu({
		})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindchange: function (e) {
    this.setData({
      currentData: e.detail.current
    })
  },
  checkCurrent: function (e) {
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }

    this.getData()
  },
  
  getData: function () {
    console.log("getData:",this.data.currentData)
    var urls = ""
    if(this.data.currentData == 0){
      urls = app.globalData.SERVER_IP+"/user/organizationSchoolBrowing/u_id/" + wx.getStorageSync('userInfo').userid+"/skip/0/limit/20"
    }else if(this.data.currentData == 1){
      urls = app.globalData.SERVER_IP+"/user/organizationCourseBrowing/u_id/" + wx.getStorageSync('userInfo').userid+"/skip/0/limit/20"
    }else if(this.data.currentData == 2){
      urls = app.globalData.SERVER_IP+"/user/organizationActivityBrowing/u_id/" + wx.getStorageSync('userInfo').userid+"/skip/0/limit/20"
    }
    var that = this
    // 获取数据
    wx.request({
      url: urls,
      method: 'GET',
      data: '',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log("获取数据", res.data.result)
        
        if(that.data.currentData == 0){
          that.setData({
            browseList: res.data.result
          })
        }else if(that.data.currentData == 1){
          that.setData({
            courseData: res.data.result
          })
        }else if(that.data.currentData == 2){
          that.setData({
            activityData: res.data.result
          })
        }
      }
    })

  }


})